package com.leo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.*;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName RadialGradientDemo
 * @Description
 * @Author wangss
 * @date 2020.07.01 13:22
 * @Version 1.0
 */
public class RadialGradientDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane an = new AnchorPane();

        GridPane gridPane = new GridPane();
        gridPane.setHgap(10d);
        gridPane.setVgap(10d);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                Rectangle rec = new Rectangle(150, 150);
                rec.setFill(Paint.valueOf("#EDEDED"));
                gridPane.add(rec, j, i);
            }
        }

        List<Paint> list = new ArrayList<>();
        Stop[] stops1 = new Stop[]{new Stop(0, Color.valueOf("#3238b0")), new Stop(0.5, Color.valueOf("#e7225e")),
                new Stop(1, Color.valueOf("#35da63"))};
        RadialGradient lg1 = new RadialGradient(0, 0, 0, 0, 100, false, CycleMethod.NO_CYCLE, stops1);
        list.add(lg1);

        Stop[] stops2 = new Stop[]{new Stop(0, Color.valueOf("#3238b0")), new Stop(0.4, Color.valueOf("#e7225e")),
                new Stop(0.8, Color.valueOf("#35da63")), new Stop(1, Color.valueOf("#FFEDC5"))};
        RadialGradient lg2 = new RadialGradient(0, 0, 100, 100, 100, false, CycleMethod.NO_CYCLE, stops2);
        list.add(lg2);

        Stop[] stops3 = new Stop[]{new Stop(0, Color.valueOf("#3238b0")), new Stop(0.4, Color.valueOf("#e7225e")),
                new Stop(0.8, Color.valueOf("#35da63")), new Stop(1, Color.valueOf("#FFEDC5"))};
        RadialGradient lg3 = new RadialGradient(0, 0, 80, 80, 100, false, CycleMethod.NO_CYCLE, stops3);
        list.add(lg3);

        Stop[] stops4 = new Stop[]{new Stop(0, Color.valueOf("#3238b0")), new Stop(0.4, Color.valueOf("#e7225e")),
                new Stop(0.8, Color.valueOf("#35da63")), new Stop(1, Color.valueOf("#FFEDC5"))};
        RadialGradient lg4 = new RadialGradient(0, 0.5, 100, 100, 45, false, CycleMethod.NO_CYCLE, stops4);
        list.add(lg4);

        Stop[] stops5 = new Stop[]{new Stop(0, Color.valueOf("#3238b0")), new Stop(0.4, Color.valueOf("#e7225e")),
                new Stop(0.8, Color.valueOf("#35da63")), new Stop(1, Color.valueOf("#FFEDC5"))};
        RadialGradient lg5 = new RadialGradient(0, 0.5, 100, 100, 90, false, CycleMethod.NO_CYCLE, stops5);
        list.add(lg5);

        Stop[] stops6 = new Stop[]{new Stop(0, Color.valueOf("#3238b0")), new Stop(0.4, Color.valueOf("#e7225e")),
                new Stop(0.8, Color.valueOf("#35da63")), new Stop(1, Color.valueOf("#FFEDC5"))};
        RadialGradient lg6 = new RadialGradient(0, 0.5, 0.5, 0.5, 0.9, true, CycleMethod.NO_CYCLE, stops6);
        list.add(lg6);

        for (int i = 0; i < list.size(); i++) {
            Rectangle rec = (Rectangle) gridPane.getChildren().get(i);
            rec.setFill(list.get(i));
        }

        an.getChildren().addAll(gridPane);

        Scene scene = new Scene(an);
        primaryStage.setScene(scene);
        primaryStage.setHeight(1000d);
        primaryStage.setWidth(1000d);
        primaryStage.setAlwaysOnTop(true);
        primaryStage.show();
    }
}
